package com.zimmor.mq.rocket_train1.delay;

import com.zimmor.mq.RocketMQProperties;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * @Author:zimmor
 * @Date: 2023/2/16 16:05
 * @Description 发送延时消息
 * @version: 1.0.0
 */

public class Producer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        DefaultMQProducer producer = new DefaultMQProducer("producer-group3");
        producer.setNamesrvAddr(RocketMQProperties.NAME_SRV_ADDR);
        producer.start();
        for (int i = 0; i < 10; i++) {
            Message message = new Message("delay", "tag", ("delayMessage" + i).getBytes());
            message.setDelayTimeLevel(3);
            SendResult sendResult = producer.send(message);
            System.out.println("sendResult = " + sendResult + LocalDateTime.now());
            TimeUnit.SECONDS.sleep(10);

        }
        producer.shutdown();
    }
}
